<!--
	作者：2575202388@qq.com
	时间：2018-10-14
	描述：诗词大会
-->
<template>
    <div style="width:100%;"> 
        <Tetable ref="tdtable" height="450" :columns="columns9" type="post" :paramiters="tj" :serverUrl="serverUrl"></Tetable>
        <edit ref="edit" v-on:reload="load()" :editparam="editparam"></edit>
        <looktm ref="looktm" :bid="bid"></looktm>
		<lookpm ref="lookpm" :bid="bid"></lookpm>
		
    </div> 
</template>
<script>
	import EditDelLook from "./EditDelLook";
	import edit from "./edit";
	import looktm from "./../../sjgl/components/sjgl/tm/manage";
	import lookpm from "./pm/manage";
    export default {
    	name: "sdchss",
    	props: {
    		tj:{
    			type: Object
    		},	
    	},
        data () {
            return {
            	serverUrl:"/host/readbook/scdh/Search_poetry.html",
                columns9: [
                    {
                        type: 'index',
                        width: 60,
                        title: '序号',
                        align: 'center'
                    },{
                        title: '诗词大会名称',
                        key: 'DHMC',
                        align: 'center',
                    },{
                        title: '开始时间',
                        key: 'KSSJ',
                        align: 'center', 
                    }, {
                        title: '结束时间',
                        key: 'JSSJ',
                        align: 'center', 
                    }, {
                        title: '最高积分',
                        key: 'TOTALSCORE',
                        align: 'center', 
                    }, {
                        title: '前多少名有积分',
                        key: 'MAXPM',
                        align: 'center', 
                    },{
                        title: '状态',
                        key: 'PSTATET',
                        align: 'center', 
						render: (h, params) => {
							return h("a", { 
						    	on: { 
						    		click: () => {
										
										if((this.user.permission && this.user.permission.indexOf("1")>-1) || this.user.uname=='admin'){
											const rows=params.row;
											this.editparam={
												pid:rows.PID, 
												dhmc:rows.DHMC,  
												kssj:rows.KSSJ, 
												jssj:rows.JSSJ, 
												pstate:rows.PSTATE,
												totalscore:rows.TOTALSCORE+"", 
												maxpm:rows.MAXPM+""
											}
											this.cosePoetry(rows.PID,rows.PSTATE);
										}else{
											this.$Modal.error({
											    title: "提示",
											    content:'对不起，您没有此权限！'
											});
										}
										
						    		}
						    	} 
							},params.row.PSTATET)
						}
                    }, 
                    {
                        title: '操作',
                        key: 'action',
                        width: 200,
                        align: 'center',
                        render: (h, params) => {
                            return h(EditDelLook, {
                            	on: {
                                    //修改诗词
                                    edit: () => {

										if((this.user.permission && this.user.permission.indexOf("1")>-1) || this.user.uname=='admin'){
											const rows=params.row;
											this.editparam={
												pid:rows.PID, 
												dhmc:rows.DHMC,  
												kssj:rows.KSSJ, 
												jssj:rows.JSSJ, 
												pstate:rows.PSTATE,
												totalscore:rows.TOTALSCORE+"", 
												maxpm:rows.MAXPM+""
											}
											this.$refs.edit.openmodal();
										}else{
											this.$Modal.error({
											    title: "提示",
											    content:'对不起，您没有此权限！'
											});
										}

                                    },
                                    //删除诗词
                                    remove: () =>{
										
										if((this.user.permission && this.user.permission.indexOf("1")>-1) || this.user.uname=='admin'){
											const rows=params.row;
											this.remove(rows.PID)
										}else{
											this.$Modal.error({
											    title: "提示",
											    content:'对不起，您没有此权限！'
											});
										}

                                    },
                                    
                                    //查看题目
                                    look: () =>{
                                    	this.bid=params.row.PID;
						           		this.$refs.looktm.modal0=true;
						           	},	 
									
									//查看排名
									lookpm: () =>{
										this.bid=params.row.PID;
										this.$refs.lookpm.modal0=true;
									},	
						           	
                                }
                            });
                        }
                    }
                ],
                editparam:{},
                bid:''
            }
        },
        computed: {
			user: function() {
				return this.$store.state.app.user;
			}
		},
		methods: {
			//删除诗词
			remove:function(pid){
                this.$Modal.confirm({
                    title: '警告',
                    content: '请确定是否删除！！！',
                    onOk: () => {
                    	//执行删除代码
                    	this.$http.get("/host/readbook/scdh/del_poetry.html?pid="+pid)
						.then(datas => {
							if(datas.result){
								//删除成功 刷新页面
								this.$Message.info('删除成功');
								this.$refs.tdtable.load();
							}else{
								//删除成功 刷新页面
								this.$Message.info(datas.msg);
								this.$refs.tdtable.load();
							}
							
						});
                    }
                });
			},
			
			
			load(){
				this.$refs.tdtable.load();
			},

			cosePoetry(pid,pstate){
				console.log(pstate);
				 if(pstate=="1"){
					this.$Modal.error({
					     title: "提示",
					     content: "已经关闭，系统排名已经生成,不能再开启！"
					});	
					return;
				}
				var params={
					pid:this.editparam.pid, 	
					totalscore:this.editparam.totalscore, 
					maxpm:this.editparam.maxpm	
				}
				this.$Modal.confirm({
				    title: '警告',
				    content: '关闭诗词后，系统会根据排名计算积分，请确定是否关闭！',
				    onOk: () => {
						this.$http.post("/host/readbook/scdh/close_poetry_pm.html",params)
						.then(result => {
							if(result){
								this.$Message.info('关闭成功');
								this.$refs.tdtable.load();
							}else{
								this.$Message.info(datas.msg);
								this.$refs.tdtable.load();
							}
						});
				    }
				});
			},
	    },
		mounted() {
		},
		watch:{
		},
		components: {
			EditDelLook,
			edit,
			looktm,
			lookpm
		}
    }
</script>


<style scoped="scoped">
	
	.ivu-table-wrapper {
		border:none;
	}
	
	.toolstipdiv{
		width: '100%';
		overflow: 'hidden';
		textOverflow: 'ellipsis';
		whiteSpace: 'normal';
		wordBreak: 'break-all';
		color:'#fff';
		text-align: center;
	}
	.toolstipdiv:hover{
		background:rgb(63, 193, 201);
	}
	
	.ivu-tooltip-rel label:hover{
		color:#0023FB;
	}
	
	.tablediv{
		height: '40px';
		overflow:'hidden';
		line-height: '40px';
	}
</style>



